﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using System.Collections.Generic;
using KenLib.BusinessManager;
using XBLib.Dal.AdoDal;
using KenLib.Common;
using System.Drawing;
using System.Reflection;

public partial class frm_TraineeFamilyInfo : System.Web.UI.Page
{
    string strErr = "";
    string strDdlDefaultText = "Lựa chọn";
    string strControlSetValue = "続柄コード,氏名,性別,生年月日,国籍,同居区分,住所１,住所２,住居国情報,電話番号,EMail,勤務先･通学先,職業名,外国人登録番号";
    int id = -1;
    public int iSessionLogin = 0;
    GlobalManager maGlobal = new GlobalManager();
    家族情報Manager ma家族情報 = new 家族情報Manager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SessionLoginID"] == null)
        {
            Response.Redirect("frm_Menu.aspx");
        }
        //Page.Form.DefaultButton = btn_登録.ID;
        //Page.Form.DefaultFocus = ddl_続柄コード.ID;
        if (Request.QueryString["id"] != null)
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
        }
        else if (Session["SessionLoginID"] != null)
        {
            id = Convert.ToInt32(Session["SessionLoginID"]);
        }
        else
        {
            Response.Redirect(AppCode_Common.getHistory(Page));
        }

        iSessionLogin = (int)Session["Login"];
        if (!IsPostBack)
        {
          //  lbl_NameHeader.Text = AppCode_Common.GetUserName(Session["SessionLoginID"].ToString());
            List<国籍> ls = maGlobal.GetAllInfoInTable<国籍>("国籍", "国籍名", true);
            ls.Insert(0, new 国籍());
            ls[0].ID = -1;
            ls[0].国籍名 = strDdlDefaultText;
            ddl_国籍.DataSource = ls;
            ddl_国籍.DataBind();
            ddl_住居国情報.DataSource = ls;
            ddl_住居国情報.DataBind();
            /*List<続柄コード> ls続柄コード = maGlobal.GetAllInfoInTable<続柄コード>("続柄コード");
            ls続柄コード.Insert(0, new 続柄コード());
            ls続柄コード[0].コード = -1;
            ls続柄コード[0].氏名 = strDdlDefaultText;
            ddl_続柄コード.DataSource = ls続柄コード;
            ddl_続柄コード.DataBind();*/
            string[] arrStr続柄 = "Cha,Mẹ,Anh,Chị,Em trai,Em gái,Vợ,Chồng,Con".Split(',');
            for (int i = 0; i < arrStr続柄.Length; i++)
            {
                ddl_続柄コード.Items.Add(new ListItem(arrStr続柄[i], (i + 1).ToString()));
            }
            for (int i = DateTime.Now.Year; i >= 1900; i--)
            {
                ddl_生年月日y.Items.Add(new ListItem(i.ToString()));
            }
            ViewState["ID"] = -1;
            ViewState["sortDirection"] = SortDirection.Ascending;
            ViewState["SortExpression"] = "続柄コード";
            if (maGlobal.GetInfoInTableByValue<本人住所情報>("本人住所情報", "社員ID", id.ToString(), false).Count == 0)
                Session["TraineeFamilyInfo"] = new List<家族情報>();
            LoadDataForGrid("続柄コード", ASCENDING);
        }
        ((MasterPage)this.Master).changeTitle("THÔNG TIN GIA ĐÌNH");
    }
    string strColumnCompareName = "";
    bool bIsASC = true;

    int CompareValueOf家族情報(家族情報 info1, 家族情報 info2)
    {
        Type type = info1.GetType();
        int iASC = bIsASC ? 1 : -1;
        PropertyInfo infoProperty = type.GetProperty(strColumnCompareName);
        object value1, value2;
        value1 = infoProperty.GetValue(info1, null);
        value2 = infoProperty.GetValue(info2, null);
        if (value1 == null)
        {
            if (value2 == null)
            {
                return 0;
            }
            else
            {
                return -1 * iASC;
            }
        }
        else
        {
            if (value2 == null)
            {
                return 1 * iASC;
            }
            else
            {
                if (infoProperty.PropertyType.Name.Contains("String"))
                    return ((string)value1).CompareTo(value2) * iASC;
                else if (infoProperty.PropertyType.Name.Contains("Int32"))
                    return ((int)value1).CompareTo(value2) * iASC;
                else
                    if (infoProperty.PropertyType.Name.Contains("Boolean"))
                        return ((bool)value1).CompareTo(value2) * iASC;
            }
        }
        return 0;
    }
    
    家族情報 GetInfoFromControls()
    {
        string[] ControlNames = strControlSetValue.Split(',');
        家族情報 info家族情報 = new 家族情報();
        Type type = info家族情報.GetType();
        foreach (string strName in ControlNames)
        {
            PropertyInfo infoProperty = type.GetProperty(strName);
            Control c = div_Body.FindControl("txt_" + infoProperty.Name);
            if (c != null)
                infoProperty.SetValue(info家族情報, AppCode_Common.getValue(infoProperty, (TextBox)c), null);
        }
        info家族情報.続柄コード = Convert.ToInt32(ddl_続柄コード.SelectedValue);
        info家族情報.続柄Name = (ddl_続柄コード.SelectedItem.Text);
        info家族情報.国籍 = Convert.ToInt32(ddl_国籍.SelectedValue);
        info家族情報.住居国情報 = Convert.ToInt32(ddl_住居国情報.SelectedValue);
        info家族情報.同居区分 = ddl_同居区分.SelectedValue == "0";
        info家族情報.性別 = ddl_性別.SelectedValue == "1";
        info家族情報.生年月日 = new DateTime(Convert.ToInt32(ddl_生年月日y.SelectedValue), Convert.ToInt32(ddl_生年月日m.SelectedValue), Convert.ToInt32(ddl_生年月日d.SelectedValue));
        info家族情報.社員ID = id;
        info家族情報.ID = Convert.ToInt32(ViewState["ID"]);
        return info家族情報;
    }

    void ViewData(int idParam)
    {
        List<家族情報> ls;
        if (idParam < 0)
        {
            ls = (List<家族情報>)Session["TraineeFamilyInfo"];
            int index = Find家族情報InListById(ls, idParam);
            if (index != -1)
                SetValueIntoControls(ls[index]);
        }
        else
        {
            ls = new GlobalManager().GetInfoInTableByValue<家族情報>("家族情報", "ID", idParam.ToString(), false);
            if (ls.Count > 0)
                SetValueIntoControls(ls[0]);
        }
    }

    void SetValueIntoControls(家族情報 info家族情報)
    {
        string[] ControlNames = strControlSetValue.Split(',');
        Type type = info家族情報.GetType();
        foreach (string strName in ControlNames)
        {
            TextBox txt = (TextBox)div_Body.FindControl("txt_" + strName);
            if (txt != null)
            {
                PropertyInfo infoProperty = type.GetProperty(strName);
                object txtValue = infoProperty.GetValue(info家族情報, null);
                if (txtValue != null)
                {
                    txt.Text = txtValue.ToString();
                }
                else txt.Text = "";
            }
        }
        ddl_続柄コード.SelectedValue = info家族情報.続柄コード.ToString();
        ddl_国籍.SelectedValue = info家族情報.国籍.ToString();
        ddl_住居国情報.SelectedValue = info家族情報.住居国情報.ToString();
        ddl_同居区分.SelectedValue = Convert.ToBoolean(info家族情報.同居区分) ? "1" : "0";
        ddl_性別.SelectedValue = Convert.ToBoolean(info家族情報.性別) ? "1" : "0";
        ddl_生年月日y.SelectedValue = Convert.ToDateTime(info家族情報.生年月日).Year.ToString();
        ddl_生年月日d.SelectedValue = Convert.ToDateTime(info家族情報.生年月日).Day.ToString();
        ddl_生年月日m.SelectedValue = Convert.ToDateTime(info家族情報.生年月日).Month.ToString();
    }

    #region Sorting and Paging
    private const string ASCENDING = " ASC";
    private const string DESCENDING = " DESC";
    private SortDirection GridViewSortDirection
    {
        get
        {
            if (ViewState["sortDirection"] == null)
                ViewState["sortDirection"] = SortDirection.Ascending;
            return (SortDirection)ViewState["sortDirection"];
        }
        set { ViewState["sortDirection"] = value; }
    }
    private void AddSortImage(int columnIndex, GridViewRow headerRow)
    {
        string[] Texts = { "Mối quan hệ", "Tên", "Tình trạng", "Điện thoại" };
        string[] Sorts = { "続柄コード", "氏名", "同居区分", "電話番号" };
        // Create the sorting image based on the sort direction.
        LinkButton lblSort = new LinkButton();
        lblSort.ID = Sorts[columnIndex];
        if (GridViewSortDirection == SortDirection.Ascending)
        {
            lblSort.Text = Texts[columnIndex] + "▲";
            lblSort.ToolTip = "Ascending Order";
        }
        else
        {
            lblSort.Text = Texts[columnIndex] + "▼";
            lblSort.ToolTip = "Descending Order";
        }
        lblSort.CssClass = "aSort";
        lblSort.Click += new EventHandler(lblSort_Click);
        // Add the image to the appropriate header cell.

        headerRow.Cells[columnIndex].Text = "";
        headerRow.Cells[columnIndex].Controls.Add(lblSort);
    }
    void LoadDataForGrid(string sortExpression, string direction)
    {
        int iTotal = 0;
        List<家族情報> ls家族情報 = new GlobalManager().SelectDataInTableAndPaging<家族情報>("家族情報", "(select value from dbo.fct_Split_With_ID(N'Cha,Mẹ,Anh,Chị,Em trai,Em gái,Vợ,Chồng,Con',',') tab1 where tab1.id=続柄コード) 続柄Name", "ID", sortExpression + " " + direction, " 社員ID= " + id.ToString(), grv.PageIndex + 1, grv.PageSize, ref iTotal);
        if (ls家族情報.Count == 0 && Session["TraineeFamilyInfo"] != null)
        {
            ls家族情報 = (List<家族情報>)Session["TraineeFamilyInfo"];
            if (ls家族情報.Count > 0)
            {
                strColumnCompareName = sortExpression;
                bIsASC = (direction == ASCENDING);
                ls家族情報.Sort(CompareValueOf家族情報);
                iTotal = ls家族情報.Count;
                iTotal = (int)Math.Ceiling(Convert.ToDecimal(iTotal) / grv.PageSize);
                if (grv.PageIndex > iTotal)
                    grv.PageIndex = iTotal;
                List<家族情報> lsTemp = new List<家族情報>();
                for (int i = grv.PageSize * (grv.PageIndex); i < (grv.PageIndex + 1) * grv.PageSize && i < ls家族情報.Count; i++)
                {
                    lsTemp.Add(ls家族情報[i]);
                }
                hd_pageCount.Value = iTotal.ToString();
                grv.ShowFooter = true;
                grv.DataSource = lsTemp;
                grv.DataBind();
            }
            else
                ShowNoData();
        }
        else
        {
            if (ls家族情報.Count > 0)
            {
                if (!IsPostBack && Request.QueryString["id"] != null)
                   SetValueIntoControls(ls家族情報[0]);
                iTotal = (int)Math.Ceiling(Convert.ToDecimal(iTotal) / grv.PageSize);
                if (grv.PageIndex > iTotal)
                    grv.PageIndex = iTotal;
                hd_pageCount.Value = iTotal.ToString();
                grv.ShowFooter = true;
                grv.DataSource = ls家族情報;
                grv.DataBind();
            }
            else
            {
                ShowNoData();
            }
        }
    }
    void ShowNoData()
    {
        List<家族情報> lsTemp = new List<家族情報>();
        lsTemp.Add(new 家族情報());
        grv.ShowFooter = false;
        grv.AllowSorting = false;
        grv.DataSource = lsTemp;
        grv.DataBind();
        grv.Rows[0].Cells.Clear();//[2].ControlStyle.ForeColor = Color.Red;
        grv.Rows[0].Cells.Add(new TableCell());
        grv.Rows[0].Cells[0].ControlStyle.ForeColor = Color.Red;
        grv.Rows[0].Cells[0].ControlStyle.BorderColor = Color.Black;
        grv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
        grv.Rows[0].Cells[0].ColumnSpan = 5;
        grv.Rows[0].Cells[0].Text = "Chưa có dữ liệu mối quan hệ";
    }
    void lblSort_Click(object sender, EventArgs e)
    {
        LinkButton lblSort = sender as LinkButton;
        string sortExpression = lblSort.ID;
        GridViewSortDirection = GridViewSortDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
        LoadDataForGrid(sortExpression, GridViewSortDirection == SortDirection.Ascending ? ASCENDING : DESCENDING);
    }
    private int GetSortColumnIndex()
    {
        foreach (DataControlField field in grv.Columns)
        {
            if (field.SortExpression == (string)ViewState["SortExpression"])
            {
                return grv.Columns.IndexOf(field);
            }
        }
        return -1;
    }
    protected void grv_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "view")
        {
            int iIdParam = Convert.ToInt32(e.CommandArgument);
            ViewData(iIdParam);
            ViewState["ID"] = iIdParam;
            btn_登録.Text = "Chỉnh sửa";

        }
        else if (e.CommandName == "del")
        {
            int iIdParam = Convert.ToInt32(e.CommandArgument);
            if (iIdParam < 0)
            {
                List<家族情報> ls家族情報 = (List<家族情報>)Session["TraineeFamilyInfo"];
                int index = Find家族情報InListById(ls家族情報, iIdParam);
                if (index != -1)
                {
                    ls家族情報.RemoveAt(index);
                    Session["TraineeFamilyInfo"] = ls家族情報;
                }
            }
            else
            {
                ma家族情報.Delete家族情報(iIdParam);
            }
            LoadDataForGrid(ViewState["SortExpression"].ToString(), ((SortDirection)ViewState["sortDirection"] == SortDirection.Ascending ? " ASC" : " DESC"));
        }
        else if (e.CommandName == "Page")
        {
            int pageCount = Convert.ToInt32(hd_pageCount.Value);
            int intCurIndex = grv.PageIndex;
            switch (e.CommandArgument.ToString().ToLower())
            {
                case "first":
                    grv.PageIndex = 0;

                    break;
                case "prev":
                    if (intCurIndex > 0)
                        grv.PageIndex = intCurIndex - 1;
                    break;
                case "next":
                    if (intCurIndex < pageCount - 1)
                        grv.PageIndex = intCurIndex + 1;
                    break;
                case "last":
                    grv.PageIndex = pageCount - 1;
                    break;
            }

            LoadDataForGrid((string)ViewState["SortExpression"], GridViewSortDirection == SortDirection.Ascending ? ASCENDING : DESCENDING);
            GridViewRow gvrPager = grv.FooterRow;
            if (gvrPager == null) return;
            DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
            ddlPages.SelectedIndex = grv.PageIndex;
        }
    }
    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            GridViewRow gvrPager = grv.FooterRow;
            DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
            grv.PageIndex = ddlPages.SelectedIndex;

            LoadDataForGrid((string)ViewState["SortExpression"], GridViewSortDirection == SortDirection.Ascending ? ASCENDING : DESCENDING);
        }
        catch (LocalException ex)
        {
            strErr = ex.Message;
        }
        catch (Exception ex)
        {
            ExportFile.WriteErr(Session["id"] as string, Session["sessionManager"] as string, "", ex.Message, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            strErr = ex.Message;
        }
        //finally
        //{
        //    if (strErr != "")
        //        Response.Redirect(ConfigurationSettings.AppSettings["PAGE_ERROR"] + "?err=" + Server.UrlEncode(strErr), false);
        //}
    }
    protected void grv_DataBound(object sender, EventArgs e)
    {
        try
        {
            GridViewRow gvrPager = grv.FooterRow;
            if (gvrPager == null) return;
            DropDownList ddlPages = (DropDownList)gvrPager.Cells[0].FindControl("ddlPages");
            Label lblPageCount = (Label)gvrPager.Cells[0].FindControl("lblPageCount");
            if (ddlPages != null)
            {
                for (int i = 0; i < Convert.ToInt32(hd_pageCount.Value); i++)
                {
                    int intPageNumber = i + 1;
                    ListItem lstItem = new ListItem(intPageNumber.ToString());
                    if (i == grv.PageIndex)
                        lstItem.Selected = true;
                    ddlPages.Items.Add(lstItem);
                }
            }

            if (lblPageCount != null)
                lblPageCount.Text = hd_pageCount.Value;
        }
        catch (LocalException ex)
        {
            strErr = ex.Message;
        }
        catch (Exception ex)
        {
            ExportFile.WriteErr(Session["id"] as string, Session["sessionManager"] as string, "", ex.Message, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            strErr = ex.Message;
        }
        //finally
        //{
        //    if (strErr != "")
        //        Response.Redirect(ConfigurationSettings.AppSettings["PAGE_ERROR"] + "?err=" + Server.UrlEncode(strErr), false);
        //}
    }
    protected void grv_RowCreated(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                int sortColumnIndex = GetSortColumnIndex();
                if (sortColumnIndex >= 0)
                {
                    AddSortImage(sortColumnIndex, e.Row);
                }
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {

                for (int i = 0; i < e.Row.Cells.Count; i++)
                {
                    if (i == 0)
                        e.Row.Cells[i].ColumnSpan = e.Row.Cells.Count;
                    else
                        e.Row.Cells[i].Visible = false;

                }
            }
        }
        catch (LocalException ex)
        {
            strErr = ex.Message;
        }
        catch (Exception ex)
        {
            ExportFile.WriteErr(Session["id"] as string, Session["sessionManager"] as string, "", ex.Message, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            strErr = ex.Message;
        }
        //finally
        //{
        //    if (strErr != "")
        //        Response.Redirect(ConfigurationSettings.AppSettings["PAGE_ERROR"] + "?err=" + Server.UrlEncode(strErr), false);
        //}
    }
    protected void grv_Sorting(object sender, GridViewSortEventArgs e)
    {
        try
        {
            string sortExpression = e.SortExpression;
            ViewState["SortExpression"] = sortExpression;

            if (GridViewSortDirection == SortDirection.Ascending)
            {
                GridViewSortDirection = SortDirection.Descending;
                LoadDataForGrid(sortExpression, DESCENDING);
            }
            else
            {
                GridViewSortDirection = SortDirection.Ascending;
                LoadDataForGrid(sortExpression, ASCENDING);
            }
        }
        catch (LocalException ex)
        {
            strErr = ex.Message;
        }
        catch (Exception ex)
        {
            ExportFile.WriteErr(Session["id"] as string, Session["sessionManager"] as string, "", ex.Message, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
            strErr = ex.Message;
        }
        //finally
        //{
        //    if (strErr != "")
        //        Response.Redirect(ConfigurationSettings.AppSettings["PAGE_ERROR"] + "?err=" + Server.UrlEncode(strErr), false);
        //}
    }

    #endregion
    protected void btn_次_Click(object sender, EventArgs e)
    {
        Response.Redirect("frm_TraineeContactInfo.aspx?id=" + id.ToString());
    }
    int Find家族情報InListById(List<家族情報> ls, int idParam)
    {
        int iReturn = -1;
        for (int i = 0; i < ls.Count && iReturn == -1; i++)
        {
            if (ls[i].ID == idParam)
            {
                iReturn = i;
            }
        }
        return iReturn;
    }
    bool Validation()
    {
        bool bReturn = true;
        string strControlRequireValueName = "ddl_続柄コード,txt_氏名,ddl_性別,ddl_生年月日d,ddl_生年月日m,ddl_生年月日y,ddl_国籍,ddl_同居区分,txt_住所１,ddl_住居国情報";
        string strControlRequireValueText = "Mối quan hệ ,Tên,Giới tính ,Ngày sinh,Ngày sinh,Ngày sinh,Quốc tịch,Tình trạng ,Nơi ở hiện tại,Quốc gia cư trú";
        string[] arrStrControlRequireValueName = strControlRequireValueName.Split(',');
        string[] arrStrControlRequireValueText = strControlRequireValueText.Split(',');
        for (int i = 0; i < arrStrControlRequireValueName.Length && bReturn; i++)
        {
            Control c = div_Body.FindControl(arrStrControlRequireValueName[i]);
            if (c != null)
            {
                if (c.GetType().Name == "TextBox" && ((TextBox)c).Text == "")
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "show", "alert('Hãy nhập thông tin " + arrStrControlRequireValueText[i] + "');", true);
                    c.Focus();
                    bReturn = false;
                }
                else if (c.GetType().Name == "DropDownList" && ((DropDownList)c).SelectedValue == "-1")
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "show", "alert('Hãy nhập thông tin " + arrStrControlRequireValueText[i] + "');", true);
                    c.Focus();
                    bReturn = false;
                }
            }
        }
        if (bReturn)
        {
            if (DateTime.DaysInMonth(Convert.ToInt32(ddl_生年月日y.SelectedValue), Convert.ToInt32(ddl_生年月日m.SelectedValue)) < Convert.ToInt32(ddl_生年月日d.SelectedValue))
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "show", "alert('Ngày không hợp lệ');", true);
                ddl_生年月日d.Focus();
                bReturn = false;
            }
        }
        return bReturn;
    }
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        if (Validation())
        {
            家族情報 info家族情報 = GetInfoFromControls();
            if (Session["TraineeFamilyInfo"] == null)
            {
                string strColumnsName = "廃止区分,続柄コード,続柄,登録年月日,修正年月日,氏名,フリガナ,性別,生年月日,年齢,国籍,同居区分,死亡年月日,備考,同伴区分,郵便番号,住所１" +
                                        ",住所２,住居国情報,電話番号,EMail,勤務先･通学先,職業名,外国人登録番号,家族年収,家族手当発生日,家族手当申請理由,家族手当,配偶者控除区分" +
                                        ",配偶者控除発生日,配偶者控除申請理由,扶養控除区分,扶養控除発生日,扶養控除申請理由,障害控除区分,社員ID";
                //info家族情報.ID = -1;//insert
                ma家族情報.Ins_Upd家族情報(info家族情報, strColumnsName);
            }
            else
            {
                List<家族情報> ls家族情報 = (List<家族情報>)Session["TraineeFamilyInfo"];
                if (btn_登録.Text == "Chỉnh sửa")
                {
                    int index = Find家族情報InListById(ls家族情報, Convert.ToInt32(info家族情報.ID));
                    ls家族情報[index] = info家族情報;
                }
                else
                {
                    info家族情報.ID = (ls家族情報.Count + 1) * -1;
                    ls家族情報.Add(info家族情報);
                }
                Session["TraineeFamilyInfo"] = ls家族情報;
            }
            
            LoadDataForGrid(ViewState["SortExpression"].ToString(), ((SortDirection)ViewState["sortDirection"] == SortDirection.Ascending ? " ASC" : " DESC"));
            btn_リセット_Click(btn_リセット, new EventArgs());
        }
    }
    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        foreach (Control c in div_Body.Controls)
        {
            if (c.GetType().Name == "TextBox")
            {
                ((TextBox)c).Text = "";
            }
            else if (c.GetType().Name == "DropDownList")
            {
                ((DropDownList)c).SelectedIndex = 0;
            }
            else if (c.GetType().Name == "CheckBox")
            {
                ((CheckBox)c).Checked = false;
            }
            else if (c.GetType().Name == "RadioButton")
            {
                ((RadioButton)c).Checked = false;
            }
        }
        btn_登録.Text = "Nhập mới";
        ViewState["ID"] = -1;
    }
}
